import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    // baseUrl: "https://jussevent.1meeting.com/admin/", // 默认前端地址
    // baseAPIUrl: "https://jussevent.1meeting.com/api", // 默认后端地址
    baseUrl: "https://register.shdengshi.com/", // 默认前端地址
    baseAPIUrl: "https://register.shdengshi.com/api", // 默认后端地址
    // 基本信息
    loginToken: JSON.parse(localStorage.getItem("ADMINLOGINTOKEN")) || "", // 登录验证token
    loginUserId: JSON.parse(localStorage.getItem("ADMINLOGINUSERID")) || "", // 登录用户id
    loginUserType: JSON.parse(localStorage.getItem("ADMINLOGINUSERTYPE")) || "", // 登录用户类型
    loginUserName: JSON.parse(localStorage.getItem("ADMINLOGINUSERNAME")) || "", // 登录用户名
  },
  mutations: {
    // 更新token
    set_loginToken(state, value) {
      state.loginToken = value;
      if (value != "") {
        localStorage.setItem("ADMINLOGINTOKEN", JSON.stringify(value));
      } else {
        localStorage.removeItem("ADMINLOGINTOKEN");
      }
    },
    // 更新登录id
    set_loginUserId(state, value) {
      state.loginUserId = value;
      if (value != "") {
        localStorage.setItem("ADMINLOGINUSERID", JSON.stringify(value));
      } else {
        localStorage.removeItem("ADMINLOGINUSERID");
      }
    },
    // 更新登录类型
    set_loginUserType(state, value) {
      state.loginUserType = value;
      if (value != "") {
        localStorage.setItem("ADMINLOGINUSERTYPE", JSON.stringify(value));
      } else {
        localStorage.removeItem("ADMINLOGINUSERTYPE");
      }
    },
    // 更新登录用户名
    set_loginUserName(state, value) {
      state.loginUserName = value;
      if (value != "") {
        localStorage.setItem("ADMINLOGINUSERNAME", JSON.stringify(value));
      } else {
        localStorage.removeItem("ADMINLOGINUSERNAME");
      }
    },
    /********************************************************************************/
    /********************************************************************************/
    /********************************************************************************/
  },
  actions: {},
  modules: {},
});
